USE [Musicman]
GO

if  not exists (select top 10 * from musicman.information_schema.tables where table_catalog = 'Musicman'
	and table_schema = 'dbo' and table_name = 'UserDownloads')
begin 

CREATE TABLE [dbo].[UserDownloads](
	[UserID] [bigint] NOT NULL,
	[SearchFielID] [bigint] NOT NULL,
 CONSTRAINT [PK_UserDownloads] PRIMARY KEY CLUSTERED 
(
	[UserID] ASC,
	[SearchFielID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
end 
GO
 
 
 /* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
COMMIT
BEGIN TRANSACTION
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.UserDownloads ADD CONSTRAINT
	FK_UserDownloads_Users FOREIGN KEY
	(
	UserID
	) REFERENCES dbo.Users
	(
	Personid
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.UserDownloads ADD CONSTRAINT
	FK_UserDownloads_SearchFile FOREIGN KEY
	(
	SearchFielID
	) REFERENCES dbo.SearchFile
	(
	SearchFileID
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
COMMIT
  